/**
 * Copyright 2012 Simple-Jdbc-Lightweight

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package org.mlu.jdbc.simple.utils;

/**
 *
 * Default SQL data type to Java type mappings for object generator. Data types
 * depend on JDBC driver implementation.
 *
 * @author Mlungisi Sincuba
 * @since 1.0
 */
import java.math.BigDecimal;
import java.sql.Types;
import java.util.TreeMap;

class DataTypeMappings {

    public static java.util.Map<Integer, String> TYPE_MAPPINGS = new TreeMap<Integer, String>();

    protected static boolean isNumber(Object obj) {

        return obj instanceof Integer || obj instanceof BigDecimal
                || obj instanceof Double || obj instanceof Long;

    }

    static {
        TYPE_MAPPINGS.put(Types.BIT, "Boolean");
        
        TYPE_MAPPINGS.put(Types.BLOB, "java.sql.Blob");
        TYPE_MAPPINGS.put(Types.CLOB, "java.sql.Clob");

        TYPE_MAPPINGS.put(Types.DATE, "java.sql.Date");
        TYPE_MAPPINGS.put(Types.TIME, "java.sql.Time");
        TYPE_MAPPINGS.put(Types.TIMESTAMP, "java.sql.Timestamp");

        TYPE_MAPPINGS.put(Types.VARCHAR, "String");
        TYPE_MAPPINGS.put(Types.CHAR, "String");
        TYPE_MAPPINGS.put(Types.LONGVARCHAR, "String");

        TYPE_MAPPINGS.put(Types.INTEGER, "Integer");
        TYPE_MAPPINGS.put(Types.TINYINT, "Integer");
        TYPE_MAPPINGS.put(Types.SMALLINT, "Integer");

        TYPE_MAPPINGS.put(Types.BIGINT, "Long");

        TYPE_MAPPINGS.put(Types.NUMERIC, "java.math.BigDecimal");
        TYPE_MAPPINGS.put(Types.DECIMAL, "java.math.BigDecimal");

        TYPE_MAPPINGS.put(Types.REAL, "Float");

        TYPE_MAPPINGS.put(Types.FLOAT, "Double");
        TYPE_MAPPINGS.put(Types.DOUBLE, "Double");
        
        TYPE_MAPPINGS.put(Types.BINARY, "byte[]");
        TYPE_MAPPINGS.put(Types.VARBINARY, "byte[]");
        TYPE_MAPPINGS.put(Types.LONGVARBINARY, "byte[]");

    }
}
